package com.blog.controller.jump;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONArray;
import com.blog.common.base.BaseController;
import com.blog.entity.sys.Role;
import com.blog.entity.sys.User;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
public class JumpController {

	private static final String LOGIN = "login";



	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index()
	{
		//TODO这里还要判断是否登陆
		return "login";  
	}  

	//login页面跳转 
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login()
	{
		return "login";
	}  


	/**
	 * 
	 * @Description: 作用:{安全退出} 
	 */
	@GetMapping("/logout")
	public String logout(HttpSession session)
	{
		session.removeAttribute("currentRole");
		session.removeAttribute("currentMenu");
		//清除shiro
		SecurityUtils.getSubject().logout();
		//session.invalidate();  //shiro里面自带有清除 功能 所以不要在写
		String url="redirect:/login";//重定向
		return url;
	}

	//主页面跳转
	@GetMapping("/index")
	public ModelAndView IndexPage(HttpSession session)
	{
		User user=(User) session.getAttribute("currentUser");
		Role role=(Role) session.getAttribute("currentRole"); 
		JSONArray menu= (JSONArray) session.getAttribute("currentMenu"); 
		Map<String,Object> map=new HashMap<>();
		map.put("userName",user.getUsername());
		map.put("roleName",role.getName());
		map.put("menu",menu);
		return BaseController.view("index",map);
	}

	//主页内容 页面跳转 
	@RequestMapping(value = "/index_content", method = RequestMethod.GET)
	public String index_content()
	{
		return "index/index_content";
	} 

	//用户列表页面跳转 
	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public String userPage()
	{
		return "user/user";
	}  


	//用户列表页面跳转 
	@RequestMapping(value = "/menu", method = RequestMethod.GET)
	public String menuPage()
	{
		return "sys/menu/menu";
	}  


	//用户列表页面跳转 
	@RequestMapping(value = "/role", method = RequestMethod.GET)
	public String rolePage()
	{
		return "sys/role/role";
	} 
	
	//发布文章 跳转 
	@RequestMapping(value = "/article", method = RequestMethod.GET)
	public String addActivePage()
	{
		return "active/addActive";
	}  

	//文章类型 跳转
	@RequestMapping(value = "/activeType", method = RequestMethod.GET)
	public String activeType()
	{
		return "active/activeType";
	} 
	
	//文章标签 跳转
	@RequestMapping(value = "/activeTag", method = RequestMethod.GET)
	public String activeTag()
	{
		return "active/activeTag";
	}  
	
	
	//文章标签 跳转
	@RequestMapping(value = "/activeList", method = RequestMethod.GET)
	public String activeListPage()
	{
		return "active/activeList";
	}  
	
	
	//首页轮播图   跳转
	@RequestMapping(value = "/website/pic", method = RequestMethod.GET)
	public String websitePic()
	{
		return "website/pic";
	}  
	
	//首页 标题   跳转
	@RequestMapping(value = "/website/nav", method = RequestMethod.GET)
	public String websiteNav()
	{
		return "website/nav";
	}  
	
	//首页  通知   跳转 
	@RequestMapping(value = "/website/notice", method = RequestMethod.GET)
	public String websiteNotice()
	{
		return "website/notice";
	}  
	
	//首页  推荐    跳转 
	@RequestMapping(value = "/website/recommend", method = RequestMethod.GET)
	public String websiteRecommend()
	{
		return "website/recommend";
	}  
	
	//首页  名言   跳转 
	@RequestMapping(value = "/website/wisdom", method = RequestMethod.GET)
	public String websiteWisdom()
	{
		return "website/wisdom";
	}  
}
